#include <sys/types.h>
#include <unistd.h>

#include <chrono>
#include <iostream>
#include <mutex>
#include <thread>
using namespace std;
mutex m1;
mutex m2;
int main() {
  cout << "pid = " << getpid() << endl;
  thread t1([]() {
    m1.lock();
    using namespace std::literals;
    std::this_thread::sleep_for(std::chrono::seconds(2));
    m2.lock();
    m2.unlock();
    m1.unlock();
  });
  thread t2([]() {
    m2.lock();
    using namespace std::literals;
    std::this_thread::sleep_for(std::chrono::seconds(2));
    m1.lock();
    m1.unlock();
    m2.unlock();
  });
  t1.join();
  t2.join();
}
// g++ -o dead_lock dead_lock.cc -std=c++17 -lpthread -g